<template>
  <el-dialog
    :title="state.title"
    @close="handleClose"
    width="600"
    v-model="state.visible"
    :before-close="beforeClose"
    :loading="state.loading"
    :close-on-press-escape="false"
    :close-on-click-modal="false"
    append-to-body
    destroy-on-close
  >
    <div>
      <yt-crud
        v-bind="options"
        ref="crudRef"
        @onLoad="getData"
        :fun-props="{
          exportBtn: false,
          delBtn: false,
          addBtn: false,
          hide: true,
        }"
        :table-props="{
          index: false,
          selection: false,
          delBtn: false,
          pageHide: true,
          viewBtn: false,
          editBtn: false,
          menu: false,
        }"
        :form-props="{
          loading: state.form.loading,
          width: 500,
        }"
        :loading="state.loading"
        :total="state.total"
        v-model:page="state.page"
        v-model:query="state.query"
      >
      </yt-crud>
    </div>

    <template #footer>
      <el-button @click="handleClose" :loading="state.loading">{{t('crud.closeText')}}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>

import YtCrud from '@/components/common/yt-crud.vue'
import {IColumn} from '@/components/common/types/tableCommon'

import {useI18n} from 'vue-i18n'

const { t } = useI18n()

const state = reactive({
  visible: false,
  loading: false,
  recharge: {},
  form: {
    loading: false,
  },
  title: t('business.customer.quotaAmount'),
  page: {
    pageSize: 30,
    pageNum: 1,
  },
  total: 0,
  query: {},
})

const column = ref<IColumn[]>(
  [
    {
      label: t('business.customer.quota.discount'),
      key: 'discount',
    },
    {
      label: t('business.customer.quota.amount'),
      key: 'amount',
    },
  ]
)

const openDialog = (row?: any) => {
  data.value = row.quotaAmount
  state.visible = true
}

const handleClose = () => {
  state.visible = false
}

const beforeClose = (done: () => void) => {
  done()
}
defineExpose({
  openDialog,
})

const crudRef = ref()
const data = ref<any[]>([])
const getData = () => {
}


const options = reactive({
  ref: 'crudRef',
  data,
  column,
})
</script>
